package com.base.library.bindadapter.statusView

import android.view.View.OnClickListener
import androidx.databinding.BindingAdapter
import com.base.library.widget.MultipleStatusView

class MultipleStatusViewExt {
    companion object {
        @JvmStatic
        @BindingAdapter(
            value = ["status", "hintText", "btnText", "onRetryClick"],
            requireAll = false
        )
        fun setStatus(
            view: MultipleStatusView,
            @MultipleStatusView.State status: Int = MultipleStatusView.State.STATUS_CONTENT,
            hintText: String?,
            btnText: String?,
            retryClickListener: OnClickListener? = null
        ) {
            when (status) {
                MultipleStatusView.State.STATUS_CONTENT -> {
                    view.showContent()
                }
                MultipleStatusView.State.STATUS_EMPTY -> {
                    view.showEmpty(hintText)
                }
                MultipleStatusView.State.STATUS_LOADING -> {
                    view.showLoading(hintText)
                }
                MultipleStatusView.State.STATUS_ERROR -> {
                    view.showError(hintText, btnText)
                }
                MultipleStatusView.State.STATUS_NETWORK_ERROR -> {
                    view.showNoNetwork(hintText, btnText)
                }
            }
            view.setOnRetryClickListener(retryClickListener)
        }
    }
}